const { series, dest, src } = require('gulp')
const htmlmin = require('gulp-htmlmin')
const htmlminOptions = {
  collapseWhitespace: true,
  collapseBooleanAttributes: true,
  removeComments: true,
  removeEmptyAttributes: true,
  removeScriptTypeAttributes: true,
  removeStyleLinkTypeAttributes: true,
  minifyJS: true,
  minifyCSS: true

}
const uglify = require('gulp-uglify-es').default
const ts = require('gulp-typescript')
const tsProject = ts.createProject('tsconfig.json')
const del = require('delete')

function clean (cb) {
  return del(['dist'])
}

function compile () {
  return tsProject.src().pipe(tsProject()).js.pipe(uglify()).pipe(dest('dist'))
}

function html () {
  return src('src/**/*.html').pipe(htmlmin(htmlminOptions)).pipe(dest('dist'))
}

function js () {
  return src('src/**/*.js').pipe(uglify()).pipe(dest('dist'))
}

exports.clean = clean
exports.compile = compile
exports.html = html
exports.js = js
exports.default = series(clean, compile, html, js)
